package com.ht;

import com.ht.memcached.MemCachedOpt;
import com.ht.power3d.vmap.DataPoint;
import com.ht.ui.ValueHandler;

import java.util.List;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: Wangjiaxiang
 * Date: 12-3-27
 */
public class ValueHandlerImpl implements ValueHandler {

    public void updateValuesOfStation(List<DataPoint> dataPoints) {
        String name;
        String key;
        for (DataPoint point : dataPoints) {
            name = point.getName();
            key = name + "." + point.getVoltageLevel();
            point.setValue(Float.valueOf(MemCachedOpt.get(key).toString()));
        }
    }

    public Map<String, Double> getHighestValues() {
        Object voltage_high_values = MemCachedOpt.get("voltage_highest_values");
        if (voltage_high_values instanceof Map)
            return (Map)voltage_high_values;
        else
            return null;
    }

    public Map<String, Double> getLowestValues() {
        Object voltage_high_values = MemCachedOpt.get("voltage_lowest_values");
        if (voltage_high_values instanceof Map)
            return (Map)voltage_high_values;
        else
            return null;
    }
}
